package rexsee.core.browser;

import rexsee.core.browser.clazz.JavascriptInterface;

public class RexseeBrowserTouchEvent implements JavascriptInterface {

	public static final String INTERFACE_NAME = "BrowserTouchEvent";
	@Override
	public String getInterfaceName() {
		return mBrowser.application.resources.prefix + INTERFACE_NAME;
	}
	@Override
	public JavascriptInterface getInheritInterface(Browser childBrowser) {
		return childBrowser.touchEvent;
	}
	@Override
	public JavascriptInterface getNewInterface(Browser childBrowser) {
		return new RexseeBrowserTouchEvent(childBrowser);
	}

	private final Browser mBrowser;
	public RexseeBrowserTouchEvent(Browser browser) {
		super();
		mBrowser = browser;
	}

	public String getType() {
		return mBrowser.touchEventInfo.type;
	}
	public int getX() {
		return Math.round(mBrowser.touchEventInfo.x / mBrowser.application.screenDensity);
	}
	public int getY() {
		return Math.round(mBrowser.touchEventInfo.y / mBrowser.application.screenDensity);
	}
	public int getX2() {
		return Math.round(mBrowser.touchEventInfo.x2 / mBrowser.application.screenDensity);
	}
	public int getY2() {
		return Math.round(mBrowser.touchEventInfo.y2 / mBrowser.application.screenDensity);
	}
	public long getDownTime() {
		return mBrowser.touchEventInfo.downTime;
	}
	public long getTime() {
		return mBrowser.touchEventInfo.eventTime;
	}
	public long getDuration() {
		return mBrowser.touchEventInfo.eventTime - mBrowser.touchEventInfo.downTime;
	}
	public int getVelocityX() {
		return mBrowser.touchEventInfo.velocityX;
	}
	public int getVelocityY() {
		return mBrowser.touchEventInfo.velocityY;
	}

	public void listenToTouchMove(boolean listen) {
		mBrowser.styleSheet.event_touchmove = (listen) ? "true" : "false";
	}
	public boolean isListeningToTouchMove() {
		return mBrowser.styleSheet.event_touchmove.equalsIgnoreCase("true");
	}

}
